package com.atguigu.controller;


import com.atguigu.entity.*;
import com.atguigu.result.RetVal;
import com.atguigu.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author zhufeiyu
 * @since 2021-12-30
 */
@RestController
@RequestMapping("/sku")
public class SkuDetailController {

    @Autowired
    private SkuDetailService skuDetailService;
    @Autowired
    private BaseCategoryViewService categoryViewService;
    @Autowired
    private SkuInfoService skuInfoService;

    //1.根据商品skuId查询商品基本信息
    //http://127.0.0.1/product/querySalePropertyByProductId/12
    @GetMapping("getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {
        return skuDetailService.getSkuInfo(skuId);
    }

    //2.根据三级分类id获取商品的分类信息
    @GetMapping("getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable Long category3Id) {
        return categoryViewService.getById(category3Id);
    }

    //3.根据skuId获取商品的实时价格
    @GetMapping("getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId) {
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo.getPrice();
    }

    //4.获取该sku所有的spu销售属性(很多)与sku的销售属性(一个)
    @GetMapping("getSpuSalePropertyAndSelected/{productId}/{skuId}")
    public List<ProductSalePropertyKey> getSpuSalePropertyAndSelected(@PathVariable Long productId,@PathVariable Long skuId) {
        return skuDetailService.getSpuSalePropertyAndSelected(productId, skuId);
    }

    //5.查询销售属性组合与skuid的一个对应关系
    @GetMapping("getSalePropertyAndSkuIdMapping/{productId}")
    public Map<Object, Object> getSalePropertyAndSkuIdMapping(@PathVariable Long productId) {
        return skuDetailService.getSalePropertyAndSkuIdMapping(productId);
    }





}

